﻿using LandManager.Web.Service;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace LandManager.Web.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/
        LandService landService = new LandService();
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Welcome()
        {
            var model = landService.GetInfoMoedelWithSQL();
            return View(model);
        }

        [HttpPost]
        public ActionResult QueryStatistic()
        {
            string sql = @"SELECT	b.type_name AS name,	ISNULL(SUM(land_area), 0) AS value
                            FROM	(SELECT * FROM LandInfo) a
                            RIGHT JOIN landtype b ON a.land_type = b.type_name
                            GROUP BY	b.type_name
                            order by value desc";
            //sql = String.Format(sql, Key);
            var list = landService.QueryLandWithSQL(sql);

            return Content(JsonConvert.SerializeObject(list));
            //return Json(list, JsonRequestBehavior.AllowGet);
        }

    }
}
